package io.github.luyanfei

class Question {

	String title,content,feedback
	Double defaultMark=1.0,penalty=0.0
	String qtype
	Boolean hidden=false
	Date dateCreated,lastUpdated
	User createdBy,modifiedBy
	List answers

	QuestionType getQuestionType(){
		qtype ? QuestionType.byName(qtype) : null
	}
	void setQuestionType(QuestionType questionType){
		qtype = questionType.name
	}

	static transients = ['questionType']
	static hasMany = [answers:QuestionAnswer]
	static constraints = {
		title blank: false
		qtype inList: QuestionType.values()*.name
		createdBy nullable: true
		modifiedBy nullable: true
	}
	static mapping = { qtype sqlType: 'varchar(20)' }
}
